package com.muyu.system.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.muyu.common.core.annotation.Excel;
import com.muyu.common.core.annotation.Excel.ColumnType;
import com.muyu.common.core.web.domain.BaseEntity;
import com.muyu.system.domain.req.SysConfigAddReq;
import com.muyu.system.domain.req.SysConfigUpdReq;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

/**
 * 参数配置表 sys_config
 *
 * @author muyu
 */
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("sys_config")
public class SysConfig extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * 参数主键
     */
    @Excel(name = "参数主键", cellType = ColumnType.NUMERIC)
    @TableId( type = IdType.AUTO)
    private Long configId;

    /**
     * 参数名称
     */
    @Excel(name = "参数名称")
    private String configName;

    /**
     * 参数键名
     */
    @Excel(name = "参数键名")
    private String configKey;

    /**
     * 参数键值
     */
    @Excel(name = "参数键值")
    private String configValue;

    /**
     * 系统内置（Y是 N否）
     */
    @Excel(name = "系统内置", readConverterExp = "Y=是,N=否")
    private String configType;

    @NotBlank(message = "参数名称不能为空")
    @Size(min = 0, max = 100, message = "参数名称不能超过100个字符")
    public String getConfigName () {
        return configName;
    }

    @NotBlank(message = "参数键名长度不能为空")
    @Size(min = 0, max = 100, message = "参数键名长度不能超过100个字符")
    public String getConfigKey () {
        return configKey;
    }

    @NotBlank(message = "参数键值不能为空")
    @Size(min = 0, max = 500, message = "参数键值长度不能超过500个字符")
    public String getConfigValue () {
        return configValue;
    }

    /**
     * 通过请求参数直接构建数据库
     * @param addReq 请求对象
     * @return 添加对象
     */
    public static SysConfig addReqBuild(SysConfigAddReq addReq) {
        return builder()
                .configKey(addReq.getConfigKey())
                .configName(addReq.getConfigName())
                .configValue(addReq.getConfigValue())
                .configType(addReq.getConfigType())
                .remark(addReq.getRemark())
                .build();
    }
    /**
     * 通过请求参数直接构建数据库
     * @param updReq 请求对象
     * @return 添加对象
     */
    public static SysConfig updReqBuild(SysConfigUpdReq updReq, Long sysConfigId) {
        return builder()
                .configId(sysConfigId)
                .configKey(updReq.getConfigKey())
                .configName(updReq.getConfigName())
                .configValue(updReq.getConfigValue())
                .configType(updReq.getConfigType())
                .remark(updReq.getRemark())
                .build();
    }
}
